﻿Imports System.Data.OleDb

Public Class DatabassProvider
    Public Shared _connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=QLNS.mdb"
    Public Shared connection As OleDbConnection
    Public Shared Sub OpenConnection()
        Try
            connection = New OleDbConnection(_connectionString)
            connection.Open()
        Catch

        End Try

    End Sub

    Public Shared Sub CloseConnection()
        If connection IsNot Nothing Then
            connection.Close()
        End If
    End Sub

    Public Shared Function ExcuQuery(ByVal sql As String) As DataTable
        OpenConnection()
        Dim dt As New DataTable()
        Dim command As OleDbCommand = connection.CreateCommand()
        command.CommandText = sql
        Dim adapter As New OleDbDataAdapter()
        adapter.SelectCommand = command
        adapter.Fill(dt)
        CloseConnection()
        Return dt
    End Function

    Public Shared Sub ExcuNonQuery(ByVal sql As String)
        OpenConnection()
        Dim command As OleDbCommand = connection.CreateCommand()
        command.CommandText = sql
        command.ExecuteNonQuery()
        CloseConnection()
    End Sub
End Class
